package hivi.vn.hivigold.activities;

import hivi.vn.hivigold.database.WebService;
import hivi.vn.hivigold.objects.Employee;

import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;

public class SelectEmployee extends ListActivity {
	ArrayList<Employee> arr;
	public static final String SELECTED_EMPLOYEE = "SELECTED_EMPLOYEE";
	public static final int SELECTED_EMPLOYEE_KEY = 2;
	protected void onCreate(android.os.Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		arr = WebService.getEmployee(this);
		ArrayAdapter<Employee> arrAdapter = new ArrayAdapter<Employee>(this, android.R.layout.simple_list_item_1, arr);
		setListAdapter(arrAdapter);
		ListView lv = getListView();
		lv.setOnItemClickListener(onItemClickListener);
	};
	
	OnItemClickListener onItemClickListener = new OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			Employee e = arr.get(arg2);
			Intent i = new Intent();
			Bundle bundle = new Bundle();
			bundle.putSerializable(SELECTED_EMPLOYEE, e);
			i.putExtras(bundle);
			setResult(RESULT_OK, i);
			finish();
		}
	};
}
